var newsPicArray
    =getNewsPicArray(document.getElementsByClassName("first")[0]);//显示对应图片,对应的链接，文字
//console.log(newspicArray);
var len =newsPicArray.length;
var  flag;
//轮播开始位置

var current =0;
function showPic(whichpic) {
    //新闻图片显示区域
    var  placeholder =document.getElementById("placeholder");
    //显示新闻标题和链接的对象
    var description =document.getElementById("description");
    //显示内容区域
    var imgSrc =whichpic.getAttribute("data-image");
    //标题
    var newsTitle =whichpic.getAttribute("title");
    //链接地址
    var url =whichpic.getAttribute("data-url");
    console.log(imgSrc+"|"+newsTitle+"|"+url);
    //设置内容
    placeholder.setAttribute("src",imgSrc);
    description.setAttribute("href",url);
    description.innerText=newsTitle;
    whichpic.parentElement.style.backgroundColor="#ff0000"
}
//默认显示的图片新闻 获得Li 的子标签
console.log(document.getElementsByClassName("first")[0].firstChild);
//showPic(document.getElementsByClassName("first")[0].firstChild);
//图片轮播 定时器
// setInterval() setTimeout()
//获取图片新闻的相关顺序 访问图片新闻（li）,相关数据存放到集合中。
function getNewsPicArray(cur) {
    var _arr =[];
    while (cur && cur.nodeType===1){
        _arr.push(cur);
        cur =cur.nextElementSibling;
    }
    return _arr;

}
function circleShowPic() {
    showPic(newsPicArray[current].firstChild);
    flag = setInterval(function () {
        current=++current>len-1?0:current;
        showPic(newsPicArray[current].firstChild);
        newsPicArray[current===0? len -1 :current -1].removeAttribute("style");
    }, 2000);}
//更改后的A标签点击处理：重置定时器
function  clickShowPic(whichPic) {
    //    停止定时器
    clearInterval(flag);
    //去除图片轮播中当前Li标签的背景色
    newsPicArray[current].removeAttribute("style");
    //    获取点击的索引, 利用A标签的信息
    current = parseInt(whichPic.innerText)-1;
    circleShowPic()


}
circleShowPic();